import pymysql

db = pymysql.connect(host='localhost', port=3306, user='root', passwd='123456', database='test_123', charset='utf8')

sql = 'insert book(name) value(%s)'
book_list = []
for i in range(0, 100000):
    book_list.append('book_name{}'.format(i))

cursor = db.cursor()
try:
    cursor.executemany(sql, book_list)
    db.commit()
except Exception:
    db.rollback()
cursor.close()
db.close()
